package Service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import Model.Qiandao;
import Dao.QiandaoMapper;
import Service.QiandaoService;
import utils.ReturnData;
import utils.ReturnDataForLayui;
import utils.UpdateOrInsertResultDeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class QiandaoServiceImpl implements QiandaoService {
    @Autowired
    private QiandaoMapper qiandaoMapper;

    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
    @Override
    public ReturnDataForLayui getList(Qiandao qiandao) {
        PageHelper.startPage(qiandao.getPage(),qiandao.getLimit());
        List<Qiandao> list = qiandaoMapper.getList(qiandao);
        PageInfo<Qiandao> info = new PageInfo<>(list);
        return ReturnDataForLayui.success(list,info.getTotal());
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public ReturnData add(Qiandao qiandao) {
        int i = qiandaoMapper.add(qiandao);
        return UpdateOrInsertResultDeal.dealWith(i);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public ReturnData delete(Qiandao qiandao) {
        int i = qiandaoMapper.delete(qiandao);
        return UpdateOrInsertResultDeal.dealWith(i);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public ReturnData update(Qiandao qiandao) {
        int i = qiandaoMapper.update(qiandao);
        return UpdateOrInsertResultDeal.dealWith(i);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public ReturnData updateState(Qiandao qiandao) {
        int i = qiandaoMapper.updateState(qiandao);
        return UpdateOrInsertResultDeal.dealWith(i);
    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
    @Override
    public ReturnDataForLayui getAlarmList(Qiandao qiandao) {
        PageHelper.startPage(qiandao.getPage(),qiandao.getLimit());
        List<Qiandao> list = qiandaoMapper.getAlarmList(qiandao);
        PageInfo<Qiandao> info = new PageInfo<>(list);
        return ReturnDataForLayui.success(list,info.getTotal());
    }


}
